package com.travel.controller.open;

import com.travel.model.dto.comment.RatingStats;
import com.travel.model.dto.common.ApiResponse;
import com.travel.model.dto.destination.DestinationDTO;
import com.travel.model.entity.content.Comment;
import com.travel.service.Service.DestinationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;
// 公开景点接口 , 获取所有景点, 获取景点详情, 按城市获取景点, 搜索景点, 获取目的地评论, 获取目的地评分统计
@Tag(name = "公开景点接口", description = "景点查询相关接口")
@RestController
@RequestMapping("/api/public/destinations")
@RequiredArgsConstructor
public class PublicDestinationController {

    private final DestinationService destinationService;

    @Operation(summary = "获取所有景点")
    @GetMapping
    public ApiResponse<Page<DestinationDTO>> getAllDestinations(Pageable pageable) {
        return ApiResponse.success("获取成功", destinationService.getAllPublicDestinations(pageable));
    }

    @Operation(summary = "获取景点详情")
    @GetMapping("/{id}")
    public ApiResponse<DestinationDTO> getDestination(
            @Parameter(description = "景点ID") 
            @PathVariable Long id) {
        return ApiResponse.success("获取成功", destinationService.getDestinationById(id));
    }

    @Operation(summary = "按城市获取景点")
    @GetMapping("/city/{city}")
    public ApiResponse<List<DestinationDTO>> getDestinationsByCity(
            @Parameter(description = "城市名称") 
            @PathVariable String city) {
        return ApiResponse.success("获取成功", destinationService.getDestinationsByCity(city));
    }

    @Operation(summary = "搜索景点", description = "支持景点名称、描述、城市的模糊搜索")
    @GetMapping("/search")
    public ApiResponse<Page<DestinationDTO>> searchDestinations(
            @Parameter(description = "搜索关键词") 
            @RequestParam String keyword,
            Pageable pageable) {
        return ApiResponse.success("获取成功", destinationService.searchDestinations(keyword, pageable));
    }

    @Operation(summary = "获取目的地评论")
    @GetMapping("/{destinationId}/comments")
    public ApiResponse<List<Comment>> getComments(
        @Parameter(description = "目的地ID") @PathVariable Long destinationId) {
        return ApiResponse.success("获取成功", destinationService.getComments(destinationId));
    }

    @Operation(summary = "获取目的地评分统计")
    @GetMapping("/{destinationId}/rating")
    public ApiResponse<RatingStats> getDestinationRating(
        @Parameter(description = "目的地ID") @PathVariable Long destinationId) {
        return ApiResponse.success("获取成功", destinationService.getDestinationRating(destinationId));
    }
} 